#!/bin/sh
#--
# The script start memcachedb and page talk application
#--

MCDB="/opt/memcachedb/"
MCDBBIN=$MCDB"bin/memcachedb"
DBDIR="/opt/mcdata/"
DBUSER="mysql"
DBLOG="/opt/mcdata/log/"
PTAPPDIR="/opt/luren/dcolors/pagetalk/luren/app/"
DBPIDLIST="/tmp/memcachedb_pid_list"
CGIPIDLIST="/tmp/cgi_pid_list"

RUN_STATE()
{
    if [ $? -ne 0 ];then
        echo $1" start failed"
    else
        echo "start "$1
#        echo $! >> $2
    fi
}
#start user base info  database 
#[master]
#MA=$MCDBBIN" -p 12501 -d -r -H "$DBDIR"PT_UDB -N -R 127.0.0.1:39801 -M -n 2 -u "$DBUSER" -v >"$DBLOG"pt_udb.log 2>&1"

MA1=$MCDB"bin/memcachedb -p 12501 -d -r -H "$DBDIR"PT_UDB -N -n 2 -u "$DBUSER" -v >/dev/null"
`nohup $MA1 > /dev/null 2>&1 &`
echo $MA1
RUN_STATE udb $DBPIDLSIT
#[replcas]
#`$MCDB"bin/memcachedb -p 12502 -d -r -H "$DBDIR"PT_UDB_R -N -R 127.0.0.1:39802 -O 127.0.0.1:39801 -S -n 2 -v >"$DBLOG"pt_udb_r.log 2>&1"

#run user extend info database
#[master]
#MA=$MCDB"bin/memcachedb -p12503 -d -r -H "$DBDIR"PT_UMSG -N -R 127.0.0.1:39803 -M -n 2 -u "$DBUSER" -v>"$DBLOG"pt_umsg.log 2>&1"

MA2=$MCDB"bin/memcachedb -p 12503 -d -r -H "$DBDIR"PT_UMSG -N -n 2 -u "$DBUSER" -v >/dev/null"
`nohup $MA2 > /dev/null 2>&1 &`
RUN_STATE umsg $DBPIDLIST
#run user rabit message database
#[master]
#MA=$MCDB"bin/memcachedb -p12505 -d -r -H "$DBDIR"PT_URS -N -R 127.0.0.1:39805 -M -n 2 -u "$DBUSER" -v>"$DBLOG"pt_urs.log 2>&1"

MA3=$MCDB"bin/memcachedb -p 12505 -d -r -H "$DBDIR"PT_URS -N -n 2 -u "$DBUSER" -v >/dev/null"
`nohup $MA3 > /dev/null 2>&1 &`
RUN_STATE urs $DBPIDLIST
#run user talk message database
#[master]
MA4=$MCDB"bin/memcachedb -p 12510 -d -r -H "$DBDIR"PT_UTMSG -N -n 2 -u "$DBUSER" -v >/dev/null"
`nohup $MA4 > /dev/null 2>&1 &`
RUN_STATE utmsg $DBPIDLIST
#run user micro blog database
MA5=$MCDB"bin/memcachedb -p 12520 -d -r -H "$DBDIR"PT_UMBLOG -N -n 2 -u "$DBUSER" -v >/dev/null"
`nohup $MA5 > /dev/null 2>&1 &`
RUN_STATE umblog $DBPIDLIST
#run rss database
MA6=$MCDB"bin/memcachedb -p 12530 -d -r -H "$DBDIR"PT_URSS -N -n 2 -u "$DBUSER" -v >/dev/null"
`nohup $MA6 > /dev/null 2>&1 &`
RUN_STATE umblog $DBPIDLIST
echo "Memcachedb Done"

#USER_RUN=$PTAPPDIR"user/run.py 8051 fastcgi"
#`$USER_RUN` & 
#RUN_STATE "comm app" $DBPIDLIST
#PING_RUN=$PTAPPDIR"ping/run.py 8099 fastcgi"
#`$PING_RUN` & 
#RUN_STATE "ping app" $DBPIDLIST
#MSG_RUN=$PTAPPDIR"msg/run.py 8058"
#`MSG_RUN` & >
#RUN_STATE "msg app" $DBPIDLIST
exit 0
